/**   
* @Title: ShiyixuanwuUtils.java 
* @Package com.esun.util 
* @Description: TODO(专供11选5使用的工具类) 
* @author Miko baoz@500wan.com   
* @date 2011-1-21 下午02:35:48  
*/
package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk;

import android.view.View;
import android.widget.TextView;

import com.esun.util.log.EDebug;

/** 
 * @ClassName: ShiyixuanwuUtils 
 * @Description: TODO(集合了一些11选5用到的工具方法) 
 * @author Miko baoz@500wan.com
 * @date 2011-1-21 下午02:35:48 
 *  
 */
public class ShiyixuanwuUtils {
    
    
    /** 
    * @Title: getHead3VoteLinCount 
    * @Description: TODO(获得11选5直选3注数) 
    * @return int    11选5直选3的注数
    */
    public static int getHead3VoteLineCount(){
        
        EDebug.o(ShiyixuanwuUtils.class.getClass(),"Getting Head3VoteLine");
        
        String[] str1 = null;
        StringBuilder sb1 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1();
        String[] str2 = null;
        StringBuilder sb2 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace2();
        String[] str3 = null;
        StringBuilder sb3 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace3();
        
        int voteLine = 0;
        
        if(sb1.length()>0){
            str1 = sb1.toString().split(",");
        }
        if(sb2.length()>0){
            str2 = sb2.toString().split(",");
        }
        if(sb3.length()>0){
            str3 = sb3.toString().split(",");
        }
        
        if(str1 != null && str2 != null && str3 != null){
            for(int i=0;i<str1.length;i++){
                for(int j=0;j<str2.length;j++){
                    if(!str1[i].equals(str2[j])){
                        for(int k=0;k<str3.length;k++){
                            if((!str3[k].equals(str2[j])) && (!str3[k].equals(str1[i]))){
                                voteLine ++;
                            }
                        }
                    }
                }
            }
        }
        return voteLine;
    }
    
    
    /** 
    * @Title: getHead2VoteLineCount 
    * @Description: TODO(获得11选5直选2注数) 
    * @return int    11选5直选2的注数
    */
    public static int getHead2VoteLineCount(){
        
        String[] str1 = null;
        StringBuilder sb1 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1();
        String[] str2 = null;
        StringBuilder sb2 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace2();
        
        int voteLine = 0;
        
        if(sb1.length()>0){
            str1 = sb1.toString().split(",");
        }
        if(sb2.length()>0){
            str2 = sb2.toString().split(",");
        }
        
        
        if(str1 != null && str2 != null){
            for(int i=0;i<str1.length;i++){
                for(int j=0;j<str2.length;j++){
                    if(!str1[i].equals(str2[j])){
                         voteLine ++;
                    }
                }
            }
        }
        
        return voteLine;
    }
    
    /** 
    * @Title: getDrect1VoteLineCount 
    * @Description: TODO(获得11选5直选1注数) 
    * @return int    11选5直选1的注数
    */
    public static int getDrect1VoteLineCount(){
        
        String[] str1 = null;
        StringBuilder sb1 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1();
        
        int voteLine = 0;
        
        if(sb1.length()>0){
            str1 = sb1.toString().split(",");
        }
        
        if(str1 != null){
            voteLine = str1.length;
        }
        
        return voteLine;
    }
    
    
    /** 
    * @Title: getFreeVoteLineCount 
    * @Description: TODO(得到任选的注数) 
    * @return int   任选注数 
    */
    public static int getFreeVoteLineCount(){
        
        String[] str1 = null;
        StringBuilder sb1 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1();
        
        int voteLine = 0;
        
        if(sb1.length()>0){
            str1 = sb1.toString().split(",");
        }
        
        if(str1 != null){
            if(str1.length >= ShiyixuanwuPlayStyle.getPlayStyle().getStyle()){
                voteLine = Combination.getCount(str1, ShiyixuanwuPlayStyle.getPlayStyle().getStyle());
            }
        }
        return voteLine;
    }
    
    /** 
    * @Title: getPlayingID 
    * @Description: TODO(获得玩法id) 
    * @return String  玩法id
    */
    public static void getPlayingID(){
        
        int detail = ShiyixuanwuPlayStyle.getPlayStyle().getDetail();
        int style = ShiyixuanwuPlayStyle.getPlayStyle().getStyle();
        
        if(detail != 0 && style != 0){
            
            if(detail == 2){
                if(style == 1){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("244");
                }else if(style == 2){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("245");
                }else if(style ==3){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("246");
                }
            }else if(detail == 3){
                if(style == 2){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("247");
                }else if(style == 3){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("248");
                }
            }else if(detail == 1){
                if(style == 2){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("249");
                }else if(style == 3){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("250");
                }else if(style == 4){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("251");
                }else if(style == 5){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("252");
                }else if(style == 6){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("253");
                }else if(style == 7){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("254");
                }else if(style == 8){
                    ShiyixuanwuBuyingInfo.getBuyingInfo().setPlayingID("255");
                }
            }
        }
    }
    
    
    /** 
    * @Title: getFreeLottery 
    * @Description: TODO(得到任选方式投注内容) 
    * @return String    任选方式投注内容
    */
    public static String getFreeLottery(){
        
        StringBuilder sbTemp = new StringBuilder();
        sbTemp = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1();
        sbTemp = LotteryUtils.sbAddZero(sbTemp);
        
        return sbTemp.toString();
    }
    
    
    /** 
    * @Title: getGroupLottery 
    * @Description: TODO(得到组选方式投注内容) 
    * @return String   组选方式投注内容
    */
    public static String getGroupLottery(){
        
        return getFreeLottery();
    }
    
    public static String getHeadLottery(int howMany){
        
        StringBuilder sbTemp = new StringBuilder();
        StringBuilder sbTempSpace2;
        StringBuilder sbTempSpace3;
        
        if(howMany == 1){
            
            sbTemp.append(getFreeLottery());
            for(int i=0;i<4;i++){
                sbTemp.append("|-");
            }
            
        }else if(howMany == 2){
            
            sbTempSpace2 = new StringBuilder();
            
            sbTempSpace2 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace2();
            
            sbTempSpace2 = LotteryUtils.sbAddZero(sbTempSpace2);
            
            sbTemp.append(getFreeLottery()).append("|").append(sbTempSpace2);
            
            for (int i = 0; i < 3; i++) {
                sbTemp.append("|-");
            }
            
        }else if(howMany == 3){
            
            sbTempSpace2 = new StringBuilder();
            sbTempSpace3 = new StringBuilder();
            
            sbTempSpace2 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace2();
            sbTempSpace3 = ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace3();
            
            sbTempSpace2 = LotteryUtils.sbAddZero(sbTempSpace2);
            sbTempSpace3 = LotteryUtils.sbAddZero(sbTempSpace3);
            
            sbTemp.append(getFreeLottery()).append("|").append(sbTempSpace2).append("|").append(sbTempSpace3);
            
            for (int i = 0; i < 2; i++) {
                sbTemp.append("|-");
            }
        }
        
        
//        sbTemp.setLength(sbTemp.length()-1);
        return sbTemp.toString();
    }
    
    /** 
    * @Title: showBuyNum 
    * @Description: TODO(显示购买确认已选号码) 
    * @param tv1 第一键盘所选号码显示
    * @param tv2 第二键盘所选号码显示
    * @param tv3 第三键盘所选号码显示
    * @return void  
    */
    public static void showBuyNum(TextView tv1,TextView tv2,TextView tv3){
        
        if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 1 ){
            tv1.setText("前一直选：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
            tv2.setVisibility(View.GONE);
            tv3.setVisibility(View.GONE);
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 2){
            if(ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 1){
                tv1.setText("任选二： " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
                tv2.setVisibility(View.GONE);
                tv3.setVisibility(View.GONE);
            }else if(ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2){
                tv1.setText("前二直选：前一  " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
                tv2.setText("           前二  " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace2()));
                tv3.setVisibility(View.GONE);
            }else if(ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 3){
                tv1.setText("前二组选： " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
                tv2.setVisibility(View.GONE);
                tv3.setVisibility(View.GONE);
            }
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 3){
            if(ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 1){
                tv1.setText("任选三 ：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
                tv2.setVisibility(View.GONE);
                tv3.setVisibility(View.GONE);
            } else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2) {
                tv1.setText("前三直选：前一  " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
                tv2.setText("           前二  " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace2()));
                tv3.setText("           前三  " + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace3()));
            } else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 3) {
                tv1.setText("前三组选：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
                tv2.setVisibility(View.GONE);
                tv3.setVisibility(View.GONE);
            }
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 4){
            tv1.setText("任选四：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
            tv2.setVisibility(View.GONE);
            tv3.setVisibility(View.GONE);
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 5){
            tv1.setText("任选五：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
            tv2.setVisibility(View.GONE);
            tv3.setVisibility(View.GONE);
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 6){
            tv1.setText("任选六：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
            tv2.setVisibility(View.GONE);
            tv3.setVisibility(View.GONE);
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 7){
            tv1.setText("任选七：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
            tv2.setVisibility(View.GONE);
            tv3.setVisibility(View.GONE);
        }else if(ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 8){
            tv1.setText("任选八：" + cutUpStringBuilder(ShiyixuanwuBuyingInfo.getBuyingInfo().getSpace1()));
            tv2.setVisibility(View.GONE);
            tv3.setVisibility(View.GONE);
        }
        
    }
    private static String cutUpStringBuilder(StringBuilder sb){
        String strCutUpSB=sb.toString();
        String[] cutUpSB=strCutUpSB.split(",");
        String result;
        
        for(int i=0;i<cutUpSB.length;i++){
            if(cutUpSB[i].length()==1){
                cutUpSB[i]="0"+cutUpSB[i];
            }else{
                
            }
        }
        if(cutUpSB.length<1){
            result=null;
        }else if(cutUpSB.length==1){
            result=cutUpSB[0];
        }else{
            result=cutUpSB[0];
            for(int i=1;i<cutUpSB.length;i++){
                result+=(","+cutUpSB[i]);
            }
        }
        return result;        
    }
}
